<?php
namespace Wap\Service;

class SessionService
{
	//private static $expire	=	7200;

	// public static function set_uploader( $data = null )
	// {
	// 	$prefix = "uploader";
	// 	session( $prefix, $data );
	// }

	// public static function get_uploader()
	// {
	// 	$prefix = "uploader";
	// 	$uploader = session( $prefix );
	// 	return $uploader;
	// }

	public static function set_smscode( $telephone, $smscode )
	{
		$prefix = "telephone";
		session( $prefix."_".$telephone."_time", time() );
		session( $prefix."_".$telephone."_smscode", $smscode );
	}

	public static function get_smscode( $telephone, $time )//the time is strict, error will occur without $time passed into
	{
		$prefix = "telephone";
        $result = array( "error" => 302, "code" => "" );//302: smscode do not change, 200: get code successfully, 204: no code exist //about return code, please reference HTTP status code
		$scopeStoreAt = session( $prefix."_".$telephone."_time" );
        $result['code'] = session( $prefix."_".$telephone."_smscode" );
        $scopeIn = time() - intval( $scopeStoreAt );

        if( empty( $result['code'] ) || $scopeIn > $time )
        {
            $result['error'] = 204;
            return $result;
        }

        if( $scopeIn < $time )
        {
             $result['error'] = 302;
             return $result;
        }

        $result['error'] = 200;
		return $result;
	}
}
?>

